Skip to content

Add configurable preflight status code for CORS middleware - #2765

Open
dneto wants to merge 2 commits into
labstack:masterfrom
dneto:preflight_status_code
Open

dneto wants to merge 2 commits into
labstack:masterfrom
dneto:preflight_status_code

Conversation

@dneto

@dneto dneto commented Apr 11, 2025 •

Copy link
Copy Markdown

Hello! I'm adding support to configurable status code for CORS preflight response.

Changes:

  • middleware/cors.go:
    • Adds the field PreflightStatusCode to CORSConfig struct
    • Sets http.NoContent as default value for PreflightStatusCode field, keeping the original behavior
  • middleware/cors_test.go
    • Add TestCORSWithConfig_PreflightStatusCode with both default and custom status code scenarios

According do MDN Reference both 200 and 204 are allowed, but checking this spec it says any 2XX is an ok status which made me create PreflightStatusCode as an int rather than a bool ReturnStatusOkInPreflight or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants